package com.yanqu.road.server.cmd.zhaoshang;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.zhaoshang.ZhaoShangProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.zhaoshang.ZsModule;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.zhaoshang.ZsMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;

@Cmd(code = Protocol.S_ZS_PROJECT_TOP_RANK_WORSHIP, desc = "膜拜")
public class ZsWeekRankWorShipCmd extends AbstractCommand {


    private int rankType;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsWeekRankWorShipReqMsg reqMsg  = ZhaoShangProto.ZsWeekRankWorShipReqMsg.parseFrom(packet.getBytes());
        rankType = reqMsg.getRankType();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ZhaoShangProto.ZsWeekRankWorShipRespMsg.Builder respMsg = ZhaoShangProto.ZsWeekRankWorShipRespMsg.newBuilder();
        if(!ZsMgr.isZsSystemOpenTime()){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        }else if(!SystemOpenMgr.systemOpen(player, eSystemId.ZhaoShang.getValue())){
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
        }else{
            Property reward = new Property();
            ret = player.getModule(ZsModule.class).worShip(rankType, reward);
            if (ret == 0 && !reward.isNothing()) {
                respMsg.setReward(PropertyHelper.parsePropertyToString(reward));
            }
        }
        respMsg.setRet(ret);
        player.sendPacket(Protocol.U_ZS_PROJECT_TOP_RANK_WORSHIP, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
